package com.ruoyi.patrol.service.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.patrol.mapper.PtDailyFormMapper;
import com.ruoyi.patrol.domain.PtDailyForm;
import com.ruoyi.patrol.service.IPtDailyFormService;

/**
 * 常用表单文件Service业务层处理
 *
 * @author lkm
 * @date 2023-11-17
 */
@Service
public class PtDailyFormServiceImpl implements IPtDailyFormService {
    @Autowired
    private PtDailyFormMapper ptDailyFormMapper;

    /**
     * 查询常用表单文件
     *
     * @param id 常用表单文件ID
     * @return 常用表单文件
     */
    @Override
    public PtDailyForm selectPtDailyFormById(Long id) {
        return ptDailyFormMapper.selectPtDailyFormById(id);
    }

    @Override
    public List<PtDailyForm> selectPtThatDayFormNotFilledInList(PtDailyForm ptDailyForm) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(ptDailyForm.getCreateTime());
        calendar.add(Calendar.DAY_OF_MONTH, 1);
        ptDailyForm.setUpdateTime(calendar.getTime());
        return ptDailyFormMapper.selectPtThatDayFormNotFilledInList(ptDailyForm);
    }

    /**
     * 查询常用表单文件列表
     *
     * @param ptDailyForm 常用表单文件
     * @return 常用表单文件
     */
    @Override
    public List<PtDailyForm> selectPtDailyFormList(PtDailyForm ptDailyForm) {
        ptDailyForm.setSchoolId(SecurityUtils.getSchoolId());
        return ptDailyFormMapper.selectPtDailyFormList(ptDailyForm);
    }

    @Override
    public List<PtDailyForm> selectPtThatDayFormList() {
        PtDailyForm ptDailyForm = new PtDailyForm();
        Calendar calendar = Calendar.getInstance();
        // 将时、分、秒和毫秒设置为零
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        ptDailyForm.setCreateTime(calendar.getTime());
        ptDailyForm.setUpdateTime(new Date());
        ptDailyForm.setSchoolId(SecurityUtils.getSchoolId());
        return ptDailyFormMapper.selectPtThatDayFormList(ptDailyForm);
    }

    /**
     * 新增常用表单文件
     *
     * @param ptDailyForm 常用表单文件
     * @return 结果
     */
    @Override
    public int insertPtDailyForm(PtDailyForm ptDailyForm) {
        ptDailyForm.setCreateTime(DateUtils.getNowDate());
        ptDailyForm.setUpdateTime(DateUtils.getNowDate());
        ptDailyForm.setCreateBy(SecurityUtils.getNickName());
        ptDailyForm.setSchoolId(SecurityUtils.getSchoolId());
        return ptDailyFormMapper.insertPtDailyForm(ptDailyForm);
    }

    /**
     * 修改常用表单文件
     *
     * @param ptDailyForm 常用表单文件
     * @return 结果
     */
    @Override
    public int updatePtDailyForm(PtDailyForm ptDailyForm) {
        ptDailyForm.setUpdateTime(DateUtils.getNowDate());
        return ptDailyFormMapper.updatePtDailyForm(ptDailyForm);
    }

    /**
     * 批量删除常用表单文件
     *
     * @param ids 需要删除的常用表单文件ID
     * @return 结果
     */
    @Override
    public int deletePtDailyFormByIds(Long[] ids) {
        return ptDailyFormMapper.deletePtDailyFormByIds(ids);
    }

    /**
     * 删除常用表单文件信息
     *
     * @param id 常用表单文件ID
     * @return 结果
     */
    @Override
    public int deletePtDailyFormById(Long id) {
        return ptDailyFormMapper.deletePtDailyFormById(id);
    }
}
